package com.bangyu.monitor.modular.system.service;

import lombok.Data;
import org.springframework.stereotype.Service;

import java.io.*;
import java.util.Objects;

/**
 * @Auther: zhangxue
 * @Date: 19/8/19 22:25
 * @Description:
 */
@Service
@Data
public class GetBinaryService {

    private boolean open;
    private String deviceNo;



    public void loadBytes(String device_no,byte[] content){
        if(open&&Objects.equals(device_no,deviceNo)){
            File file = new File("binary");
            if(!file.exists()){
                file.mkdir();

            }

            try {
                File binaryFile = new File("binary"+File.separator+device_no+".bin");
                OutputStream os = new FileOutputStream(binaryFile,true);
                os.write(content);
                os.flush();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

    public void close(){
        setOpen(false);

    }



}
